package com.qifan.alb2b.action.back;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qifan.alb2b.domain.CompanyInfoDomain;
import com.qifan.alb2b.service.CompanyInfoService;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.ID;
import com.qifan.alb2b.util.Page;

@Controller
@RequestMapping("/admin/company")
public class CompanyManageController {
	private CompanyInfoService companyInfoService;

	public void setCompanyInfoService(CompanyInfoService companyInfoService) {
		this.companyInfoService = companyInfoService;
	}

	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm, CompanyInfoDomain uqp) {
		// spring太给力了，可以自动装配两个对象 会自动的装返回的Map转换成JSON对象
		return companyInfoService.query(dgm, uqp);
	}

	@RequestMapping("/add.adm")
	@ResponseBody
	public Map<String, Object> add(CompanyInfoDomain companyInfoDomain) {
		Map<String, Object> map = new HashMap<String, Object>();
		companyInfoDomain.setCompId(ID.next() + "");// 设置唯一ID
		companyInfoDomain.setCreateTime(new Date());
		companyInfoService.add(companyInfoDomain);
		map.put("success", true);
		return map;
	}

	@RequestMapping("/update.adm")
	@ResponseBody
	public Map<String, Object> update(CompanyInfoDomain companyInfoDomain) {
		Map<String, Object> map = new HashMap<String, Object>();
		companyInfoDomain.setCreateTime(new Date());
		companyInfoService.update(companyInfoDomain);
		map.put("success", true);
		return map;
	}

	@RequestMapping("/del.adm")
	@ResponseBody
	public Map<String, Object> delete(@RequestParam("uid") String[] ids) {
		Map<String, Object> map = new HashMap<String, Object>();
		companyInfoService.getUserByCompId(ids);
		companyInfoService.delete(ids);
		map.put("success", true);
		return map;
	}

}
